package com.atguigu.webapp.controller.room;


import com.atguigu.common.result.Result;
import com.atguigu.webapp.service.RoomInfoService;
import com.atguigu.webapp.vo.room.RoomDetailVo;
import com.atguigu.webapp.vo.room.RoomItemVo;
import com.atguigu.webapp.vo.room.RoomQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "房间信息")
@RestController
@RequestMapping("/app/room")
public class RoomController {

    @Autowired
    private RoomInfoService roomInfoService;


    @Operation(summary = "分页查询房间列表")
    @Parameters({
            @Parameter(name = "current",description = "页码",in = ParameterIn.QUERY),
            @Parameter(name = "size",description = "每页查询数量",in = ParameterIn.QUERY),
            @Parameter(name = "queryVo",description = "返回给前端的查询结果vo对象",in = ParameterIn.QUERY)

    })
    @GetMapping("pageItem")
    public Result<IPage<RoomItemVo>> pageItem(@RequestParam long current,
                                              @RequestParam long size, RoomQueryVo queryVo) {
        IPage<RoomItemVo> iPage = new Page<>(current,size);
        IPage<RoomItemVo> voIPage = roomInfoService.pageItem(iPage,queryVo);
        return Result.ok(voIPage);
    }

    @Operation(summary = "根据id获取房间的详细信息")
    @Parameters({
            @Parameter(name = "id",description = "房间id",in = ParameterIn.QUERY)
    })
    @GetMapping("getDetailById")
    public Result<RoomDetailVo> getRoomDetailById(@RequestParam Long id) {
        RoomDetailVo roomDetailVo = roomInfoService.getRoomDetailById(id);
        return Result.ok(roomDetailVo);
    }

    @Operation(summary = "根据公寓id分页查询房间列表")
    @Parameters({
            @Parameter(name = "current",description = "页码",in = ParameterIn.QUERY),
            @Parameter(name = "size",description = "每页查询数量",in = ParameterIn.QUERY),
            @Parameter(name = "id",description = "公寓id",in = ParameterIn.QUERY)
    })
    @GetMapping("pageItemByApartmentId")
    public Result<IPage<RoomItemVo>> pageItemByApartmentId(@RequestParam long current,
                                                           @RequestParam long size, @RequestParam Long id) {
        IPage<RoomItemVo> iPage = new Page<>(current,size);
        Page<RoomItemVo> list = roomInfoService.pageItemByApartmentId(iPage, id);
        return Result.ok(list);
    }
}
